﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ABC.Business.Models;
using ABC.Controllers.ViewModels.My.News;

namespace ABC.Controllers.Areas.My
{
    [Authorize]
    public class NewsController : BaseController
    {
        private readonly NewsModel newsModel;

        public NewsController(NewsModel newsModel)
        {
            this.newsModel = newsModel;
        }

        public ActionResult Index(string id, string tag, string date)
        {
            var model = new NewsViewModel { CategoryNews = string.IsNullOrEmpty(id) ? string.IsNullOrEmpty(tag) ? string.IsNullOrEmpty(date) ? "all" : "date" : "tag" : id };
            if (model.CategoryNews == "tag")
            {
                model.News = newsModel.GetNewsByTag(tag);
            }
            else
            {
                model.News = newsModel.GetNews(id, date);
            }

            newsModel.GetTop10Tags();
            return View(model);
        }


        public ActionResult New(string id)
        {
            var model = new NewsItemViewModel();
            model.Item = newsModel.GetItemNews(id);
            return View(model);
        }


    }
}
